<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .myimg{
            width:200px;
            height:200px;
            display:block;
            margin:0 auto;
        }
    </style>
</head>
<body>
    <img alt="logo" src="./images/animal1.png" class="myimg"/>
</body>
<script>
    var myimg = document.getElementsByTagName("img")[0];
    //获取DOM元素的属性
    console.log(myimg.getAttribute("class"));
    //点击图片时，修改图片的src属性值
    //setAttribute("属性名"，"属性值");
    // myimg.onclick = function(){
    //     this.setAttribute("src", "./images/animal3.png");
    // }

    myimg.onclick = function(){
                this.setAttribute("src", "./images/animal3.png");
        //判断DOM元素是否存在该属性
        if(this.hasAttribute("alt")){
            //若存在，则将该属性删除
            this.removeAttribute("alt");
        }
    }

</script>
</html>